package com.itheima.api.stream.demo07;

import java.util.ArrayList;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class StreamCollect {

    public static void main(String[] args) {

        ArrayList<String> list = new ArrayList<>();

        list.add("蓝启仁");
        list.add("蓝忘机");
        list.add("蓝涣");
        list.add("蓝曦臣");
        list.add("蓝愿");
        list.add("蓝思追");
        list.add("魏婴");
        list.add("魏无羡");
        list.add("敛芳尊");
        list.add("金光瑶");
        list.add("赤锋尊");
        list.add("聂明玦");

        Stream<String> stream = list.stream();
        Set<String> set = stream.collect(Collectors.toSet());
        set.forEach(s -> System.out.println(s));

        ArrayList<String> list1 = new ArrayList<>();
        list1.add("蓝涣,25");
        list1.add("蓝曦臣,24");
        list1.add("蓝愿,15");
        list1.add("蓝思追,14");

        list1.stream().filter(s -> {
            String[] split = s.split(",");
            int age = Integer.parseInt(split[1]);
            if (age > 20){
                return true;
            } else {
                return false;
            }
        }).forEach(s -> System.out.println(s));
        System.out.println("--------------------");

        Map<String, Integer> map = list1.stream().collect(Collectors.toMap(s -> {
            String[] split = s.split(",");
            return split[0];
        }, s -> {
            String[] split = s.split(",");
            return Integer.parseInt(split[1]);
        }));
        map.forEach((key, value) -> System.out.println(key + "," + value));

    }
}
